package com.example.jiubodou.validation;

import org.springframework.util.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @ClassName MobileValidator
 * @Description
 * @Author huyingliang
 * @Date 2024-05-06 15:29
 */
public class MobileValidator implements ConstraintValidator<Mobile, String> {
    /*这两个泛型，前者是注解类型 ，后者是 要检验的值是什么类型*/

    @Override
    public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
        /*s就是前端传过来的值*/
        return StringUtils.hasText(s) && s.length() == 11 && s.startsWith("1");
    }
}
